/*---------------------------------在线或离线---------------------------------*/
$('.psSelect').on('click',function(){
	if($(this).attr('show') == 1){
		$('.optionWrap').show();
		$(this).attr('show',0);
	}else{
		$('.optionWrap').hide();
		$(this).attr('show',1);
	}
})
$('.optionWrap span.option div.onLine').on('click',function(){
	var _this = this;
	$.ajax({
		type:"POST",
		url:"/ps/task/userStatusJson",
		async:true,
		data:{
			'status':$(_this).find('div').attr('value'),
			'userId':$('.userName').attr('userId')
		},
		success:function(res){
			if(res['code'] == 200){
				$('.optionWrap').hide();
				$('.psSelect').html($(_this).html());
				$('.psSelect').attr('show',1);
				window.location.href = 'http://l.psdashi.cn';
			}else{
				alert('操作错误，请重试！');
			}
		}
	});
})
$('.optionWrap span.option div.outLine').on('click',function(){
	$('.modelLeave').show();
	$('.modelBg').show();
	$('html,body').css('overflow','hidden');
	$('.submit').attr('value',-2);
})
/*---------------------------------完成或释放----------------------------------*/
$('.numWrap').on('click',function(){
	$('.model').show();
	$('.modelBg').show();
	$('html,body').css('overflow','hidden');
	$('.complete').attr('id',$(this).attr('id'));
	$('.tuikuan').attr('id',$(this).attr('id'));
})
$('.closeModel').on('click',function(){
	$('.model').hide();
	$('.modelBg').hide();
	$('html,body').css('overflow-y','scroll');
})
$('.cancel').on('click',function(){
	$('.modelLeave').hide();
	$('.modelBg').hide();
	$('html,body').css('overflow-y','scroll');
})
$('.submit').on('click',function(){
	var _this = this;
	console.log($('.submit').attr('value'));
	$.ajax({
		type:"POST",
		url:"/ps/task/userStatusJson",
		async:true,
		data:{
			'status':$('.submit').attr('value'),
			'userId':$('.userName').attr('userId')
		},
		success:function(res){
			if(res['code'] == 200){
				$('.optionWrap').hide();
				$('.psSelect').html($('.outWrap').html());
				$('.psSelect').attr('show',1);
				window.location.href = 'http://l.psdashi.cn';
			}else{
				alert('操作错误，请重试！');
			}
		}
	});
})
//完成
$('.complete').on('click',function(){
	var _this = this;
	$.ajax({
		type:"POST",
		url:"/ps/task/finishTaskJson",
		async:true,
		data:{
			'status':4,
			'psTaskId':$(_this).attr('id'),
			'installerId':$('.userName').attr('userId')
		},
		success:function(res){
			console.log(res);
			if(res['code'] == 200){
				$('.model').hide();
				$('.modelBg').hide();
				$('html,body').css('overflow-y','scroll');
				$('#'+$(_this).attr('id')).remove();
			}else{
				alert('操作错误，请重试！');
			}
		}
	});
})
//释放
$('.tuikuan').on('click',function(){
	var _this = this;
	$.ajax({
		type:"POST",
		url:"/ps/task/finishTaskJson",
		async:true,
		data:{
			'status':-1,
			'psTaskId':$(_this).attr('id'),
			'installerId':$('.userName').attr('userId')
		},
		success:function(res){
			console.log(res);
			if(res['code'] == 200){
				$('.model').hide();
				$('.modelBg').hide();
				$('html,body').css('overflow-y','scroll');
				$('#'+$(_this).attr('id')).remove();
			}else{
				alert('操作错误，请重试！');
			}
		}
	});
})
/*--------------------------------弹框-------------------------------*/
window.onload = function(){
	var datejs= $('#datejs').val();
	getAjax();
	function getAjax(){
		$.ajax({
		    url: '/ps/task/appointedTaskNumJson',
		    type: 'GET',
		    dataType:'json',
		    data: {
		    	'timeStr':datejs,
		    	'installerId':$('#installerId').val()
		    },
		    success:function(res){
		    	var num = '';
		    	$('.messageNumRed').html(res.data);
		    	if(res.data > 0){
	    			if(! ('Notification' in window) ){
	    				alert('Sorry bro, your browser is not good enough to display notification');
	    				return;
	    			}else{
	    				Notification.requestPermission(function(permission){
		    				var notification = new Notification("您被指派了新任务",{body:res.data,icon:'http://image1.zhiwangvip.com/static/images/ps/anzhuang.png',dir:'auto'});
		    				setTimeout(function() {
		                        notification.close();
		                    }, 5000);
		    				notification.onclick = function(){
		    					notification.close();
			    				var href = window.location.href;
			    				window.location.href=href;
			    			}
		    			});
	    			}	
		    	}
		    },error:function(){
		    	
		    }
	})
	setTimeout(getAjax,5000);
}
}
